package svc

import (
	"gorm.io/gorm"
	"zero_study/common/common/init_db"
	"zero_study/rpc_user/user_gorm/models"
	"zero_study/rpc_user/user_gorm/rpc/internal/config"
)

type ServiceContext struct {
	Config config.Config
	DB     *gorm.DB
}

func NewServiceContext(c config.Config) *ServiceContext {
	//初始化 链接
	db := init_db.InitGorm(c.Mysql.DataSource)

	//数据迁移
	db.AutoMigrate(&models.UserModel{})

	return &ServiceContext{
		Config: c,
		DB:     db,
	}
}
